#include <iostream>
#include <fstream>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <string>
using namespace std;

#include <stdio.h>
#include <fcntl.h>
#include <io.h>

typedef bitset<8> Bitset8;
//----------------------------------------------------------------------------------------------------------------------
void byte2bit(const char& ch)
{
    Bitset8 in(ch);
    cout << in;
}
//----------------------------------------------------------------------------------------------------------------------
class bit2byte
{
public:
    void operator()(const char& ch)
    {
        mIn += ch;
        if (mIn.size() == 8)
        {
            Bitset8 in(mIn);
            cout << char(in.to_ulong());
            mIn.clear();
        }
    }
    size_t mCnt;
    string mIn;
};
//----------------------------------------------------------------------------------------------------------------------
typedef istreambuf_iterator<char> char_in;
//==========================================================================================================================
int main(int argc, char *argv[ ])
{
    if (argc == 2)
    {
        if (argv[1][0] == 'E')
        {
            _setmode(_fileno(stdin), _O_BINARY);
            for_each((char_in(cin)), char_in(), byte2bit);
        }
        else if (argv[1][0] == 'D')
        {
            _setmode(_fileno(stdout), _O_BINARY);
            bit2byte b2b;
            for_each((char_in(cin)), char_in(), b2b);
        }
    }
    else
    {
        cerr << "(E)ncode or (D)ecode option missing" << endl;
    }
}
